from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from apps.goods.models import SPU, Brand, GoodsCategory


class SPUModelSerializer(ModelSerializer):
    """SPU"""
    # category1 = serializers.StringRelatedField()
    # category2 = serializers.StringRelatedField()
    # category3 = serializers.StringRelatedField()
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    brand = serializers.StringRelatedField()
    brand_id =serializers.IntegerField()
    class Meta:
        model=SPU
        fields = "__all__"

        extra_kwargs = {
            "category1":{
                'required':False
            },"category2":{
                'required':False
            },"category3":{
                'required':False
            },
        }
"""
 {
        "id": "商品SPU ID",
        "name": "SPU名称",
        "brand": "品牌名称",
        "brand_id": "品牌id",
        "category1_id": "一级分类id",
        "category2_id": "二级分类id",
        "category3_id": "三级分类id",
        "sales": "SPU商品销量",
        "comments": "SPU商品评论量",
        "desc_detail": "商品详情",
        "desc_pack": "商品包装",
        "desc_service": "售后服务"
   }
"""



class BrandSimpleSerializer(ModelSerializer):
    """获取品牌信息"""
    class Meta:
        model=Brand
        fields = ['id','name']


class ChannelSerializer(ModelSerializer):
    """分类表"""
    class Meta:
        model = GoodsCategory
        fields = ['id','name']


